# -*- coding: utf-8 -*-
"""
Created on Thu May 23 23:48:28 2019

@author: Administrator
"""

# numpy 随机数
import numpy as np

# 生成随机数
# ndaray random.rand(d0, d1, .., dn): 浮点数，[0,1)，均匀分布
# d0,d1,dn:维度，可选
# 如果没有参数，返回一个float随机值
#help(np.random.rand)
print(np.random.rand())

rand = np.random.rand(2,3,4)
print(rand)

# ndarray random.randn(d0, d1, ..., dn): 标准正态分布
nrand = np.random.randn(2,3,4)
print(nrand)

# ndarray random.randint(low, high, shape): 创建随机整数数组
intrand = np.random.randint(1, 10, (2,3,4))
print(intrand)

# 数组元素顺序
# void random.shuffle(array)：原数组按第一轴变换顺序

a_data = np.random.randint(1,10,(4,3))
print(a_data)
np.random.shuffle(a_data)
print(a_data)

# ndarray random.permutation(array)：按原数组第一轴置换创建新数组
a_permutated = np.random.permutation(a_data)
print(a_permutated)

# 产生某种分布的数组
# ndarray random.uniform(low, high, shape):均匀分布
# ndarray random.normal(loc, scale, shape):正态分布, loc：均值，scale:标准差
# ndarray random.poisson(lam, shape):泊松分布，lam:随机事件发生概率
uniform = np.random.uniform(0,10,(3,4))
print(uniform)

# 统计函数
# np.sum(array, axis=None):根据axis计算数组a相关元素和
# np.mean(array, axis=None):期望
# np.average(array, axis=None, weights=None):加权平均数
# np.std(array, axis=None):标准差
# np.var(array, axis=None):方差
# np.median(a):中位数
# np.ptp(a):最大值与最小值之差
randint = np.random.randint(1,10,(3,4))
print(randint)
print(np.mean(randint,axis=1))

# 梯度函数
# 梯度：连续值之间的变化率，即斜率